﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Betfairer
{
    public class CommonSelector
    {
        // добавлять в blacklist если рынок просрочен
        //private List<Market> _blackList; // использовать другую коллекцию для более быстрого поиска
        private const long MS_PER_SECOND = 1000;
        private const long MS_PER_MINUTE = 60 * MS_PER_SECOND;
        private const long MS_PER_HOUR = 60 * MS_PER_MINUTE;

        public CommonSelector()
        {
            //_blackList = new List<Market>();
        }

        public bool SergeSelect(Market market, string requiredName)
        {
            //Console.WriteLine("Blacklist: " + _blackList.Count);
            //if (!_blackList.Contains(market))
            //{
            if (!market.MarketName.Equals(requiredName))
            {
                //_blackList.Add(market);
                return false;
            }

            bool timeCorrectness = market.EventDateMs - Utils.Now > 10 * MS_PER_MINUTE
                && market.EventDateMs - Utils.Now <= 5 * MS_PER_HOUR;

            if (timeCorrectness == false)
            {
                //_blackList.Add(market);
                return false;
            }


            Table table = new TableDao().GetTable(market.MarketId);



            if (table.InPair <= 35000)
            {
                //_blackList.Add(market);
                //Console.WriteLine(market.MarketId + " " + table.InPair);
                return false;
            }

            //Table table = new Table(Global.Instance.GetOdds(market.MarketId));

            bool isFull = Utils.Full(table);

            //Console.WriteLine(table);

            if (isFull == false)
            {
                //_blackList.Add(market);
                return false;
            }

            Console.WriteLine("[SELECTOR] Selected successully.");

            return true;
            //}
            //else
            //{
            //    return false;
            //}
        }

        //public List<Market> BlackList
        //{
        //    get
        //    {
        //        return _blackList;
        //    }
        //}
    }
}
